package com.landiao.ctrler.management;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.landiao.common.pojo.EmployeeReport;
import com.landiao.common.pojo.Page;
import com.landiao.common.pojo.PerformanceHisInfo;
import com.landiao.common.pojo.Querier;
import com.landiao.common.utils.DateUtil;
import com.landiao.ctrler.BaseCRUDCtrler;
import com.landiao.entities.Employee;
import com.landiao.entities.ItemCategory;
import com.landiao.entities.Shop;
import com.landiao.service.EmployeeReportService;
import com.landiao.service.OrderScheduleService;
import com.landiao.service.ShopService;
@Controller
@RequestMapping("/management/report")
public class ReportCtrler extends BaseCRUDCtrler<EmployeeReport, String>{
	@Autowired
	private EmployeeReportService employeeReportService;
	@Autowired
	private ShopService shopService;
	
	@RequestMapping("index")
	public String index(Model model) {
		List<ItemCategory> t = employeeReportService.getCategoryList();
		model.addAttribute("t",t);
		return "management/report/index";
	}
	@RequestMapping("serviceindex")
	public String serviceindex(Model model) {
		return "management/report/serviceindex";
	}
	@RequestMapping("outindex")
	public String outindex(Model model) {
		return "management/report/outindex";
	}
	@RequestMapping("shopindex")
	public String shopindex(Model model) {
		List<ItemCategory> t = employeeReportService.getCategoryList();
		model.addAttribute("t",t);
		return "management/report/shopindex";
	}
	@RequestMapping("commissionindex")
	public String commissionindex(Model model) {
		return "management/report/commissionindex";
	}
	@ResponseBody
	@RequestMapping("page")
	public Page<EmployeeReport> page(EmployeeReport t, Querier querier) {
		Page<EmployeeReport> page = null;
		if(t.getBegDate()!=null&&t.getShopId()!=null){
			String date =t.getBegDate(); 
			t.setBegDate(date+" 00:00:00");
			t.setEndDate(date + " 23:59:59");
			page = employeeReportService.queryByPage(querier,t);
		}
		return page;
	}
	@ResponseBody
	@RequestMapping("getReport")
	public List<EmployeeReport> getReportByShopAndDate(EmployeeReport t){
		List<EmployeeReport> list = null;
		if(t.getBegDate()!=null&&t.getEndDate()!=null&&t.getShopId()!=null){
			t.setBegDate(t.getBegDate()+" 00:00:00");
			t.setEndDate(t.getEndDate() + " 23:59:59");
			list = employeeReportService.getEmployeeReport(t);
		}
		return list;
	};
	@ResponseBody
	@RequestMapping("getServiceReport")
	public List<EmployeeReport> getServiceReport(EmployeeReport t){
		List<EmployeeReport> list = null;
		if(t.getBegDate()!=null&&t.getEndDate()!=null&&t.getShopId()!=null){
			t.setBegDate(t.getBegDate()+" 00:00:00");
			t.setEndDate(t.getEndDate() + " 23:59:59");
			list = employeeReportService.getServiceReport(t);
		}
		return list;
	};
	@ResponseBody
	@RequestMapping("getOutReport")
	public List<EmployeeReport> getOutReport(EmployeeReport t){
		List<EmployeeReport> list = null;
		if(t.getBegDate()!=null&&t.getEndDate()!=null&&t.getShopId()!=null){
			t.setBegDate(t.getBegDate()+" 00:00:00");
			t.setEndDate(t.getEndDate() + " 23:59:59");
			list = employeeReportService.getOutReport(t);
		}
		return list;
	};
	@ResponseBody
	@RequestMapping("getShopReport")
	public List<EmployeeReport> getShopReport(EmployeeReport t){
		String shopId = this.getClientUser().getUser().getShopId();
		//查询当前是否具有上级门店，如果没有就是总店的id
		Shop shop = shopService.getById(shopId);
		if(shop.getPshopId()!=null){
			t.setShopId(shopId);
		}
		List<EmployeeReport> list = null;
		if(t.getBegDate()!=null&&t.getEndDate()!=null){
			t.setBegDate(t.getBegDate()+" 00:00:00");
			t.setEndDate(t.getEndDate() + " 23:59:59");
			list = employeeReportService.getShopReport(t);
		}
		return list;
	};
	@ResponseBody
	@RequestMapping("getWageReport")
	public List<EmployeeReport> getWageReport(EmployeeReport t){
		//1.获取时间段
		String couseDate = t.getBegDate();
		t.setBegDate(DateUtil.getStartTime(DateUtil.getMonthFirstDate(DateUtil.str2Date(couseDate, "yyyy-MM"),0)).toString());
		t.setEndDate(DateUtil.getEndTime(DateUtil.getMonthLastDate(DateUtil.str2Date(couseDate, "yyyy-MM"),0)).toString());
		List<EmployeeReport> list = employeeReportService.getWageReport(t);
		return list;
	};
	
	
}
